<template>
  <div
    class="btn"
    :class="{
      primary: type == 'primary',
      success: type == 'success',
      danger: type == 'danger',
    }"
    @click="handlerClick"
  >
    <!-- 匿名插槽，由用户自主传入内容 -->
    <slot></slot>
  </div>
</template>

<script>
export default {
  props: {
    type: {
      type: String,
    },
  },
  methods: {
    handlerClick(e) {
      // console.log('子组件中响应的事件');
      // 实现子传父
      this.$emit("click", e);
    },
  },
};
</script>
<style lang='less' scoped>
// @import url("@/styles/bootstrap.css");
.btn {
  // vw：将屏幕宽度分为100份(100vw),意味着一个vw代表一份的宽度
  width: 318/360 * 100vw;
  height: 48px;
  background-color: #ccc;
  border-radius: 25px;
  line-height: 50px;
  text-align: center;
  color: #000;
  font-weight: bold;
  font-size: 20px;
  margin: 0 auto;
}
.primary {
  background-color: rgb(76, 111, 218);
  color: #fff;
}
.success {
  background-color: rgb(41, 145, 31);
  color: #fff;
}
.danger {
  background-color: rgb(236, 143, 22);
  color: #fff;
}
</style>
